/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistence;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

/**
 * Utility for accessing hibernate sessions.
 * @author Johan Boon
 */
public class SessionManager {
    
    private static final SessionFactory sessionFactory; 
     
    static {
        try {
            // Create the SessionFactory from standard (hibernate.cfg.xml) config file.
            sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            // Log the exception. 
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }
    
    // Vraag: wanneer wordt deze gebruikt?
    private SessionManager() {}

    public static Session openSession() {
        return sessionFactory.openSession();
    }

    public static void close() {
        sessionFactory.close();
    }

}
